package com.ruoyi.web.controller.cs;

import java.util.List;
import java.util.Map;

import com.ruoyi.common.core.controller.BasicsController;
import com.ruoyi.common.core.domain.Response;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.core.page.ResponsePageInfo;
import com.ruoyi.common.utils.ServletUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.cs.domain.vo.TGoodsUpgrateRecentlyVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.cs.domain.TGoodsUpgrate;
import com.ruoyi.cs.service.ITGoodsUpgrateService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 幸运饰品升级记录Controller
 * 
 * @author ruoyi
 * @date 2021-04-02
 */
@Api(tags = {"运饰品升级记录"})
@RestController
@RequestMapping("/cs/upgrate")
public class TGoodsUpgrateController extends BasicsController
{
    @Autowired
    private ITGoodsUpgrateService tGoodsUpgrateService;

    /**
     * 查询幸运饰品升级记录列表
     */
    @ApiOperation("查询幸运饰品升级记录列表")
    @PreAuthorize("@ss.hasPermi('cs:upgrate:listBack')")
    @RequestMapping(name="查询幸运饰品升级记录列表",value="listBack",method = RequestMethod.POST)
    public ResponsePageInfo<TGoodsUpgrate> listBack(@RequestBody  TGoodsUpgrate tGoodsUpgrate)
    {
        String sort = " a.create_time desc";
        if (StringUtils.isNotEmpty(tGoodsUpgrate.getSortType())) {
            if (tGoodsUpgrate.getSortType().equals("0")) {
                sort = "a.goods_price asc";
            }else {
                sort = "a.goods_price desc";
            }
        }
        startPage(tGoodsUpgrate.getPageNum(),tGoodsUpgrate.getPageSize(),sort);
        List<TGoodsUpgrate> list = tGoodsUpgrateService.selectTGoodsUpgrateList(tGoodsUpgrate);
        return toResponsePageInfo(list);
    }

    /**
     * 获取幸运饰品升级记录详细信息
     */
    @ApiOperation("获取幸运饰品升级记录详细信息")
    @PreAuthorize("@ss.hasPermi('cs:upgrate:getInfo')")
    @RequestMapping(name="查询幸运饰品升级记录列表",value="getInfo",method = RequestMethod.GET)
    @ApiImplicitParam(name = "luckyId",value = "幸运饰品升级记录ID" ,dataType = "String", paramType = "query", required = true)
    public Response<Map<String,Object>> getInfo(String luckyId)
    {
        return tGoodsUpgrateService.selectTGoodsUpgrateById(luckyId);
    }

    /**
     * 幸运饰品最近掉落
     */
    @ApiOperation("幸运饰品最近掉落")
    @RequestMapping(name="幸运饰品最近掉落",value="common/recentlyOpen",method = RequestMethod.GET)
    @ApiImplicitParam(name = "goodsId",value = "幸运饰品ID" ,dataType = "String", paramType = "query", required = true)
    public Response<List<TGoodsUpgrateRecentlyVo>> recentlyOpen(String goodsId)
    {
        return Response.success(tGoodsUpgrateService.recentlyOpen(goodsId));
    }

    @ApiOperation("幸运饰品排名")
    @GetMapping("/common/upgrateRanking")
    @ApiImplicitParam(name = "type",value = "类型 today 今日 yesterday 昨日" ,dataType = "String", paramType = "query", required = true)
    @Cacheable(value="oneSecondCache", key="'upgrateRanking'+#p0")
    public Response<List<TGoodsUpgrate>> upgrateRanking(String type){
        List<TGoodsUpgrate> list = tGoodsUpgrateService.upgrateRanking(type);
        return Response.success(list);
    }
}
